package dhm.com.dhmshop.adapter.home;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.annotation.NonNull;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.ArrayList;
import java.util.List;

import dhm.com.dhmshop.R;
import dhm.com.dhmshop.base.netWork.Constant;
import dhm.com.dhmshop.entity.GetShopDetailBean;

/**
 * Created by admin
 * 2019/4/29
 * 所有订单适配器
 */
public class ShopHomeAdapter extends RecyclerView.Adapter<ShopHomeAdapter.ViewHolder> {

    private GetShopDetailBean getShopDetailBean;
    private Context context;


    public ShopHomeAdapter(Context context) {
        this.context = context;
    }

    public void setGetShopDetailBean(GetShopDetailBean getShopDetailBean) {
        this.getShopDetailBean = getShopDetailBean;
        notifyDataSetChanged();
    }

    public void showImage(List<Bitmap> imageList) {
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        ViewHolder viewHolder;
        View view= LayoutInflater.from(context).inflate(R.layout.item_shophome, null);
        viewHolder=new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, final int i) {

        GridLayoutManager manager=new GridLayoutManager(context,2);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        viewHolder.recy.setLayoutManager(manager);
        ShopAdapter shopAdapter = new ShopAdapter(context);
        viewHolder.recy.setAdapter(shopAdapter);
        if (i==0){
            viewHolder.item_name.setText("店主推荐");
            shopAdapter.setShopList(getShopDetailBean.getData().getRecomm_goods(),getShopDetailBean.getData().getShopId()+"");
        }else if (i==1){
            viewHolder.item_name.setText("最新上映");
            shopAdapter.setShopList(getShopDetailBean.getData().getNew_goods(),getShopDetailBean.getData().getShopId()+"");
        }else if (i==2){
            viewHolder.item_name.setText("精品促销");
            shopAdapter.setShopList(getShopDetailBean.getData().getBest_goods(),getShopDetailBean.getData().getShopId()+"");
        }else if (i==3){
            viewHolder.item_name.setText("热销商品");
            shopAdapter.setShopList(getShopDetailBean.getData().getHot_goods(),getShopDetailBean.getData().getShopId()+"");
        }


    }

    @Override
    public int getItemCount() {
        int i=0;
        if (getShopDetailBean.getData().getRecomm_goods()!=null||getShopDetailBean.getData().getRecomm_goods().size()>0){
            i++;
        }
        if (getShopDetailBean.getData().getNew_goods()!=null||getShopDetailBean.getData().getNew_goods().size()>0){
            i++;
        }
        if (getShopDetailBean.getData().getBest_goods()!=null||getShopDetailBean.getData().getBest_goods().size()>0){
            i++;
        }
        if (getShopDetailBean.getData().getHot_goods()!=null||getShopDetailBean.getData().getHot_goods().size()>0){
            i++;
        }
        return i;
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        public TextView item_name;
        public RecyclerView recy;


        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            recy=itemView.findViewById(R.id.recy);
            item_name=itemView.findViewById(R.id.item_name);
        }
    }

    private OnClick onClick;
    public void setdeleteClick(OnClick onClick) {
        this.onClick = onClick;
    }
    public interface OnClick{
        void item(int posttion);
    }

    private OnIntentClick onIntentClick;
    public void setaddClick(OnIntentClick onClick) {
        this.onIntentClick = onClick;
    }
    public interface OnIntentClick{
        void item();
    }



}

